services:
  nginx:
    image: nginx
    ports:
      - 80:80
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf

  #   build:
  #     context: app
  #     dockerfile: Dockerfile
  #   ports:
  #     - 8000:8000
  #   # depends_on:
  #   #   - db
  #   environment:
  #     # DB_HOST: db
  #     # DB_USER: postgres
  #     # DB_PASSWORD: changethis
  #     DB_NAME: if-else-task2
  #     DB_TYPE: sqlite
  #     JWT_KEY: "changethis"

  backend:
    restart: always
    depends_on:
      - db
    env_file:
      - .env
    environment:
      - DOMAIN=${DOMAIN}
      - ENVIRONMENT=${ENVIRONMENT}
      - BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS}
      - SECRET_KEY=${SECRET_KEY?Variable not set}
      - POSTGRES_SERVER=db
      - POSTGRES_PORT=${POSTGRES_PORT}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER?Variable not set}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
    build:
      context: ./app
      # args:
      #   INSTALL_DEV: ${INSTALL_DEV-false}
    platform: linux/amd64 # Patch for M1 Mac

  # frontend:
  #   restart: always
  #   ports:
  #     - 8001:8001
  #   env_file:
  #     - .env
  #   volumes:
  #     - ./frontend/dist:/usr/share/nginx/html
  #   build:
  #     context: ./frontend
  #     args:
  #       - VITE_API_URL=http://${DOMAIN?Variable not set}
  #       - NODE_ENV=production

  db:
    image: postgres:12
    restart: always
    volumes:
      - app-db-data:/var/lib/postgresql/data/pgdata
    env_file:
      - .env
    ports:
      - 127.0.0.1:5432:5432
    environment:
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
      - POSTGRES_USER=${POSTGRES_USER?Variable not set}
      - POSTGRES_DB=${POSTGRES_DB?Variable not set}

  frontend:
    build: ./frontend-php

volumes:
  app-db-data:
